class DDL {
  String title;
  DateTime deadline;
  DateTime updateDate;
  DateTime completionDate;
  bool isCompleted;
  int priority;
  String task;
  DDL({
    required this.title,
    required this.deadline,
    required this.updateDate,
    required this.task,
    required this.completionDate,
    this.priority = 1,
    this.isCompleted = false,
  });
  // 将 DDL 对象转换为 Map
  Map<String, dynamic> toJson() {
    return {
      'title': title,
      'deadline': deadline.toIso8601String(),
      'updateDate': updateDate.toIso8601String(),
      'completionDate': completionDate.toIso8601String(),
      'isCompleted': isCompleted,
      'task': task,
      'priority': priority,
    };
  }

  // 从 Map 创建 DDL 对象
  factory DDL.fromJson(Map<String, dynamic> json) {
    return DDL(
      title: json['title'],
      deadline: DateTime.parse(json['deadline']),
      updateDate: DateTime.parse(
        json['updateDate'] ?? DateTime.now().toIso8601String(),
      ),
      completionDate: DateTime.parse(
        json['completionDate'] ?? DateTime.now().toIso8601String(),
      ),
      task: json['task'],
      priority: json['priority'] ?? 1,
      isCompleted: json['isCompleted'] ?? false,
    );
  }
}
